<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value='<%=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/" %>'/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<jsp:include page="/view/taglib.jsp"></jsp:include>
<jsp:include page="/view/ueditorlib.jsp"></jsp:include>
</head>
<body>
       <div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'north',split:true,border:false" style="height: 40px;">
			<table>
				<tr>
					<td><a id="btn_add" class="easyui-linkbutton" data-options="group:'g1',iconCls:'icon-add'">添加</a></td>
					<td><a id="btn_dele" class="easyui-linkbutton" data-options="group:'g1',iconCls:'icon-remove'">删除</a></td>
					<td><a onclick="grid.datagrid('reload');" href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-arrow_refresh'">刷新</a></td>
				</tr>
			</table>
		</div>
	    
    	<div data-options="region:'center',border:false" >
			<table id="grid"></table>
		</div>
  
		<div data-options="region:'east',split:true,border:false" style="width: 70%; padding: 5px;">
			<form id="form" name="form" method="post" class="form">
				<fieldset>
					<legend>
						基本信息--<span id="operateMode_title">添加模式</span>
					</legend>
					<table class="table">
						<tbody>
							<tr>
								<th>编号</th>
								<td><input id="id" name="id" readonly="readonly" value ="0" class="textbox" style="height: 22px;" /></td>
							</tr>
							<!-- <tr>
								<th>学生名称</th>
								<td><input name="name" class="textbox easyui-validatebox" style="height: 22px;" data-options="required:true" /></td>
							</tr> -->
							<tr>
								<th>添加时间</th>
								<td><input name="created" data-options="disabled:true" class="easyui-datetimebox" style="width: 180px;" /></td>
							</tr>
							<tr>
								<th>简介</th>
								<td colspan="3"><textarea id="name" name="name" style="width: 98%; margin-bottom: 3px;"></textarea> <input type="button" mode="0" class="editor" onclick="EditorRender('name',$(this))" value="切换至编辑器"></td>
							</tr>
							<tr>
								<th>操作</th>
								<td><a id="operateMode_submit" class="easyui-linkbutton" data-options="iconCls:'icon-save'">确定</a> <a id="operateMode_reset" class="easyui-linkbutton" data-options="iconCls:'icon-reload'">重置</a></td>
							</tr>
						</tbody>
					</table>
				</fieldset>
			</form>
		</div>
	</div>
<script type="text/javascript">
$(function() {
	var gird;
	grid=$('#grid').datagrid({
		fit:true,
		border : false,
		collapsible : false,
		rownumbers : true,
		pagination : true,
		singleSelect : true,
		rownumbers : true,
	    url:'../listAllFUser.do',
	    columns:[[
			{field:'id',title:'学号',width:100},
			{field:'name',title:'名字',width:100}
	    ]],
	    onLoadSuccess : function(data) {
			$('.iconImg').attr('src', fw.pixel_0);
		},
		onClickRow : function(index, row) {
			$("#form").form("load", row);
			$("#operateMode_title").html("修改模式");
		}
	});
	//添加操作
	$("#btn_add").click(function() {
		$("#operateMode_title").html("添加模式");
		$('#grid').datagrid("unselectAll");
		$("#id").attr("value", 0);
		$("#form").form("reset");
	})

	//删除操作
	$("#btn_dele").click(function() {
		var rows = $('#grid').datagrid('getSelections');
		if (rows <= 0) {
			$.messager.show({
				title : message.title.normal,
				msg : message.grid_select,
				timeout : message.timeout,
				showType : message.showType
			});
		} else {
			$.messager.confirm(message.title.askTitle, message.dele_comfirm, function(r) {
				if (r) {
					var idValue = $("#form input[name='id']").val();
					$.post("../delFUser.do", {
						id : idValue
					}, function(result) {
						if (result.success) {
							$.messager.show({
								title : message.title.normal,
								msg : message.dele_success,
								timeout : message.timeout,
								showType : message.showType
							});
							grid.datagrid('reload');
						} else {
							$.messager.show({
								title : message.title.normal,
								msg : message.dele_fail,
								timeout : message.timeout,
								showType : message.showType
							});
						}
					}, 'json');
					$("#btn_add").click();
				}
			});
		}
	})

	//确认提交操作
	$("#operateMode_submit").click(function() {
		var idValue = $("#form input[name='id']").val();
		//遍历所有编辑器，将编辑器模式切换到textarea模式，目的是为了必填的编辑器字段验证数据是否有输入
		$('.editor').each(function() {
			if ($(this).attr('mode') == 1) {
				$(this).click();
			}
		});
		//遍历所有编辑器，将编辑器模式切换到textarea模式，目的是为了必填的编辑器字段验证数据是否有输入
		$('.editor').each(function() {
			if ($(this).attr('mode') == 1) {
				$(this).click();
			}
		});
		if ($('#form').form('validate')) {
			if (idValue > 0) {
				//修改
				$.post("../updateFUser.do", fw.serializeObject($('form')), function(result) {
					console.log(result);
					if (result.success) {
						$.messager.show({
							title : message.title.normal,
							msg : message.update_success,
							timeout : message.timeout,
							showType : message.showType
						});

						grid.datagrid("reload");

						//重新获取form信息内容
						$("#form").form("load", "../getUserById.do?id=" + idValue);
					}
				}, 'json');
			} else {
				//添加
				$.post("../addFUser.do", fw.serializeObject($('form')), function(result) {
					if (result.success) {
						$.messager.show({
							title : message.title.normal,
							msg : message.add_success,
							timeout : message.timeout,
							showType : message.showType
						});
						grid.datagrid("reload");
						$("#form").form("reset");
					}
				}, 'json');
			}
		}
	})
	
	//重置操作
	$("#operateMode_reset").click(function() {
		var idValue = $("#form input[name='id']").val();
		if (idValue > 0) {
			$("#form").form("load","../getUserById.do?id=" + idValue);
		} else {
			$("#form").form("reset");
		}
	})


});
</script>
</body>
</html>